require(['./config'],()=>{
    require(['jquery'],($)=>{
        class Login{
            constructor(){
                this.login()
            }
            login(){ 
                $('.loginBtn').on('click',()=>{
                    let loginName = $('#loginName').val()
                    let loginPsw = $('#loginPassword').val()
                    // console.log(loginName,loginPsw)
                    var userList = localStorage.getItem('userList')
                    if(userList){
                        var isExist =JSON.parse(userList).some(user => {
                                return user.registerName === loginName 
                            }) 
                        if(isExist){
                            var verify = JSON.parse(userList).some(user => {
                                return user.registerName === loginName && user.registerPwd === loginPsw
                            }) 
                            if(verify){
                                alert('验证成功')
                                document.cookie=`username=${loginName};path=/`
                                location.href = '/index.html'
                            }
                            else{
                                alert('密码错误')
                            }
                        }
                        else{
                            alert('改账号未注册')
                            location.href = '/html/register.html'
                        } 
                    }else{
                        alert('请先注册')
                        location.href = '/html/register.html'
                    }
                })
          }
        
        }
        new Login()
    })
})